package stardust.product.platform.webc.spi.servlet.jsp.tag;


import javax.servlet.jsp.tagext.DynamicAttributes;
import java.util.Map;
import java.util.HashMap;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTagSupport;


/**
 * 动态属性标记抽象类。
 * <p>
 * 实现基础的支持动态属性的标签结构。
 * <p/>
 * @author ChenChang
 */
public abstract class AbstractDynamicAttributesTag extends BodyTagSupport implements DynamicAttributes
{

  private static final long serialVersionUID = 1L;

  /**
   * 动态属性
   */
  protected Map<String, Map<String, String>> attribute;

  /**
   * 解析标记开始
   */
  public abstract int doStartTag() throws JspException;

  /**
   * 解析标记正文之后
   */
  public abstract int doAfterBody() throws JspException;

  /**
   * 解析标记结尾
   */
  public abstract int doEndTag() throws JspException;

  public AbstractDynamicAttributesTag()
  {
    ;
  }

  public void setDynamicAttribute(String pre, String key, Object value)
  {
    if (this.attribute == null)
    {
      this.attribute = new HashMap<String, Map<String, String>>();
    }
    
    if (!this.attribute.containsKey(pre))
    {
      this.attribute.put(pre, new HashMap<String, String>());
    }

    this.attribute.get(pre).put(key, (String) value);
  }

}
